#include <iostream>
#include <vector>
#include <algorithm>
#include "listnode.h"
#include "common.h"
using namespace std;

class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {
        vector<int> result;
        while (head != nullptr) {
            result.push_back(head->val);
            head = head->next;
        }
        reverse(result.begin(), result.end());
        return result;
    }
};

int main() {
    cout << Solution().printListFromTailToHead(buildList({1, 2, 3, 4})) << endl;
    return 0;
}